package com.xn.app.muying.activity;

import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.xn.app.muying.R;
import com.xn.app.muying.util.APIMethod;
import com.xn.app.muying.util.BaseActivity;
import com.xn.app.muying.util.MyAlertDialog;
import com.xn.app.muying.util.NetworkUtil;
import com.xn.app.muying.util.ToastUtil;

public class GouMaiActivity extends BaseActivity {
    private WebView gou_mai=null;
    //加载框
    AlertDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gou_mai);
        findViewById(R.id.guan_bi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        gou_mai = (WebView) findViewById(R.id.gou_mai);
        gou_mai.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub

                view.loadUrl(url);
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                return true;
            }

            //页面开始加载
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            //加载结束 （其实页面404等等错误的情况也算加载完成）
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (dialog != null) {
                    dialog.dismiss();
                }
                gou_mai.setVisibility(WebView.VISIBLE);
            }
        });
        realize();
    }

    /**
     * 功能实现
     */
    private void realize() {

        //获取数据
        if (NetworkUtil.isNetworkAvailable(this)) {
                dialog = new MyAlertDialog().ShowDialog(GouMaiActivity.this, R.layout.dialog_loading);
                dialog.setCancelable(true);
//            shou_hou.getSettings().setJavaScriptEnabled(true);
            gou_mai.loadUrl(APIMethod.GouMia);
//            WebSettings mWebSettings = shou_hou.getSettings();
//            mWebSettings.setSupportZoom(true);
//            mWebSettings.setLoadWithOverviewMode(true);
//            mWebSettings.setUseWideViewPort(true);
//            mWebSettings.setDefaultTextEncodingName("GBK");
//            mWebSettings.setLoadsImagesAutomatically(true);
        } else {
            ToastUtil.showToast(this,R.string.no_network_hint);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
